package emulator.util.events;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class EventAggregator
{
	private final BlockingQueue<Event> queue;
	
	public EventAggregator()
	{
		queue = new ArrayBlockingQueue<Event>(1024);
		Consumer consumer = new Consumer();
		new Thread(consumer).start();
	}
	
	public void fire(Event event) throws InterruptedException
	{
		queue.put(event);
	}
	
	private class Consumer implements Runnable
	{
		@Override
		public void run()
		{
			try {
				for (;;)
				{
					queue.take().execute();
				}
			}
			catch (InterruptedException ex)
			{
			}
			catch (Exception ex)
			{
				
			}
		}
	}
}
